package com.godtree.util;

import java.util.List;

//封装页面数据  
public class Page {  

 private int totalrecord;  //总纪录数  
 private int pagesize = 3;  //每页多少条数据  
 private int totalpage;  

 private int pagenum;     //用户想哪一页  
 private int startindex;  //根据用户想看的页，算出该页在数据库的起始位置  

 private int startpage;  //jsp页面的起始页码  
 private int endpage;    //jsp页面的结束页码  

 private List list;   //保存页面数据 ，这里假如显示的是Book所有的记录，list里面封装的的是很多book数据。相当于getALLBook();  


 public Page(int pagenum,int totalrecord){  
  this.totalrecord = totalrecord;  
  this.pagenum = pagenum;  
    
  //构造函数根据用户传递进来的总纪录数和页号，算出总页数，和该页在数据库的起始位置  
  //1.算出总页数  
  if(this.totalrecord%this.pagesize==0){  
   this.totalpage = this.totalrecord/this.pagesize;  
  }else{  
   this.totalpage = this.totalrecord/this.pagesize + 1;  
  }  
    
  //2.算出页号在数据库的起始位置，不同数据库中不一样，mysql查询出来的结果是这个位置的下一个数据。从这个的下一个开始  
  this.startindex = (this.pagenum-1)*this.pagesize;  
    
  //3.算出jsp页面的起始页码和结束页码，小于10个，全显示，大于10个，只显示10个  
  if(this.totalpage<=10){  
   this.startpage = 1;  
   this.endpage = this.totalpage;  
  }else{    
     
   this.startpage = this.pagenum - 4;  
   this.endpage = this.pagenum + 5;  
     
   if(this.startpage<1){  
    this.startpage = 1;  
    this.endpage = 10;  
   }  
   if(this.endpage>this.totalpage){  
    this.endpage = this.totalpage;  
    this.startpage = this.totalpage-9;  
   }  
  }  
 }  

 public int getTotalrecord() {  
  return totalrecord;  
 }  
 public void setTotalrecord(int totalrecord) {  
  this.totalrecord = totalrecord;  
 }  
 public int getPagesize() {  
  return pagesize;  
 }  
 public void setPagesize(int pagesize) {  
  this.pagesize = pagesize;  
 }  
 public int getTotalpage() {  
  return totalpage;  
 }  
 public void setTotalpage(int totalpage) {  
  this.totalpage = totalpage;  
 }  
 public int getPagenum() {  
  return pagenum;  
 }  
 public void setPagenum(int pagenum) {  
  this.pagenum = pagenum;  
 }  
 public int getStartindex() {  
  return startindex;  
 }  
 public void setStartindex(int startindex) {  
  this.startindex = startindex;  
 }  

 public int getStartpage() {  
  return startpage;  
 }  

 public void setStartpage(int startpage) {  
  this.startpage = startpage;  
 }  

 public int getEndpage() {  
  return endpage;  
 }  

 public void setEndpage(int endpage) {  
  this.endpage = endpage;  
 }  

 public List getList() {  
  return list;  
 }  

 public void setList(List list) {  
  this.list = list;  
 }  


}  